<?php
namespace app\home\controller;
// use app\index\
class Service extends Base
{
    public function index()
    {
        $id=request()->param('id'); 
        $article=db("channel_service");
        $channel=db("channel");

        $viewPage=$this->getIndexPage($id);
        $fname=$channel->where("id",$id)->value("name");
        // 分页
        $p=request()->param('p'); 
        if(!$p){
            $p=1;
        }
        $psize=20;        
        $stp=($p-1)*$psize;
        
        $where['status']=1;
        $where['cid']=$id;    
        $count=$article->where($where)->count();
        $tolp=ceil($count/$psize);
        $mess=$article->where($where)->order("is_top desc,sort asc , id DESC")->limit($stp,$psize)->select();

        $pid=$channel->where("id=".$id)->value("pid");
        
        if($pid > 0){
            $gcid=$pid;
            $pcid=$id;
            $gnavName=$channel->where("id=".$gcid)->value("name");
            $lchannel=$this->get_left_channel($gcid);            
            $pnavName=$channel->where("id=".$pcid)->value("name");
        }else{
            $gcid=$id;          
            $gnavName=$channel->where("id=".$gcid)->value("name");
        }

        // 分页渲染
        $this->assign("p",$p);
        $this->assign("tolp",$tolp);
        $this->assign("count",$count);
        
        // SEO META关键字配置
        $meta=$this->getSeoMeta($gnavName,$pnavName);
        $this->assign("meta",$meta);
        
        $modelx=$channel->where("id",$id)->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);
        $banner=$this->get_banner($gcid);
        $this->assign("banner",$banner);
        $this->assign("id",$id);
        $this->assign("pcid",$pcid);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("mess",$mess);
        $this->assign("lchannel",$lchannel);
        $this->assign("gcid",$gcid);
        $this->assign("pcid",$pcid);
        $this->assign("fname",$fname);            
        return view($viewPage);
       
    }    
    public function detail()
    {
        $id=request()->param('id');       
        $article=db("channel_service");
        $channel=db("channel");

        $mess=$article->find($id);
        $where['status']=1;
        $where['tid']=$mess['id'];
        $where['tablename']="channel_service";
        $mess['photos']=db("attachment")->where("tid=".$mess['id'])->select();
        $pid=$channel->where("id=".$mess['cid'])->value("pid");
        if($pid > 0){
            $gcid=$pid;
            $pcid=$mess['cid'];
            $lchannel=$this->get_left_channel($gcid);   
            $gnavName=$channel->where("id=".$gcid)->value("name");         
            $pnavName=$channel->where("id=".$pcid)->value("name");
        }else{
            $gcid=$mess['cid'];         
            $gnavName=$channel->where("id=".$gcid)->value("name");
        }

        $fname=$channel->where("id",$mess['cid'])->value("name");
        $viewPage=$this->getDetailPage($mess['cid']);

        // SEO META关键字配置
        $meta=$this->getSeoMeta($gnavName,$pnavName,$mess);
        $this->assign("meta",$meta);

        $modelx=$channel->where("id",$mess['cid'])->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);
        $banner=$this->get_banner($gcid);
        $this->assign("banner",$banner);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("lchannel",$lchannel);
        $this->assign("pcid",$pcid);
        $this->assign("gcid",$gcid);
        $this->assign("fname",$fname);
        $this->assign("mess",$mess);
        return view($viewPage);
    }
}
